﻿using DE_MVC_WyFy.Areas.Administrator.Models.Enities;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace DE_MVC_WyFy.Areas.Administrator.Controllers
{
    public class CategoryManagerController : Controller
    {
        //
        // GET: /Administrator/CategoryManager/

        public ActionResult Index()
        {
			List<Category> lsCat = Category.Objects.All().ToList();
            return View(lsCat);
        }
		public ActionResult Detail(int id)
		{
			Category cat = Category.Objects.GetById(id);
			return View(cat);
		}
		public ActionResult Edit(int id)
		{
			Category cat = Category.Objects.GetById(id);
			return View(cat);
		}
		[HttpPost]
		public ActionResult Edit(Category cat)
		{
			if (ModelState.IsValid)
			{
				Category.Objects.Update(cat);
				return RedirectToAction("Index");
			}
			return View(cat);
		}
		public ActionResult Create()
		{
			return View();
		}
		[HttpPost]
		public ActionResult Create(Category cat)
		{
			if (ModelState.IsValid)
			{
				Category.Objects.AddWithIdentity(cat);
				return RedirectToAction("Index");
			}
			return View();
		}
    }
}
